<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class user extends MY_Controller {

    public function __construct() {
    parent:: __construct();
    $this->loadTemplate();
    $this->load->library('template'); 
    $this->load->helper("url");
    //$this->load->model('posts');
    $this->load->helper('form');
    $this->load->library('SimpleLoginSecure');
    $this->loadTemplate();
    }
    
    
      public function loadTemplate()
      {
          $this->template->write_view('header','main/header');
          $this->template->write_view('menu','main/menu');
          $this->template->write_view('slide','main/slide');
          $this->template->write_view('news','main/new');
          $this->template->write_view('footer','main/footer');
      }
    
    public function register() {
        if (isset($_POST['user_email']) and isset($_POST['user_password']))
        {
            $post= $this->input->post();
            //var_dump($post);die;
            $this->simpleloginsecure->create($_POST['user_email'],$_POST['user_password'],$post['user_name'],$post['gender'],$post['address'],$post['phone']);
            $this->template->write_view('content','user/register_success');
            $this->template->render();
        }
        else
        {
            $this->template->write_view('content','user/register');
            $this->template->render();
        }
    }
    
    public function login() {
        if (isset($_POST['user_email']) and isset($_POST['user_password']))
        {
            $this->simpleloginsecure->login($_POST['user_email'],$_POST['user_password']);
            header( 'Location:'.base_url().'home' ) ;
        }
        else
        {
            header( 'Location:'.base_url().'home' ) ;
        }
    }
    
    public function logout() {
            $this->simpleloginsecure->logout();
            header( 'Location:'.base_url().'home' ) ;
        }
}